<script setup lang="ts">
import { onMounted, ref } from "vue";
const show = ref<boolean>(false);

const props = defineProps<{
  removeNode: Function;
}>();

onMounted(() => {
  // 页面挂在后开始做动画
  show.value = true;
});
const close = () => {
  if (show.value) {
    //加这层判断主要为了防止用户频繁点击蒙版

    //动画结束后关闭弹窗
    show.value = false;
    setTimeout(() => {
      // 动画结束后移除元素
      props.removeNode();
    }, 500);
  }
};
</script>

<template>
  <div class="">
    <transition name="pop">
      <div class="pop-wrap" v-if="show">
      <!--  @click="close" -->
        <div class="mask"></div>
        <div class="pop-content">
          <div class="img-div">
            <img src="../assets/voice.png" alt="">
          </div>
        </div>
      </div>
    </transition>
  </div>
</template>

<style scoped>
.pop-wrap {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
}
.mask {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  transition: all 0.5s;
}
.pop-enter-active,
.pop-leave-active {
  /* 时长需要与各个子元素（maske、pop-content）动画时长最长的相等 */
  transition: all 0.5s;
}
.pop-enter-from .mask,
.pop-leave-to .mask {
  opacity: 0;
}
.pop-enter-to .mask,
.pop-leave-from .mask {
  opacity: 1;
}
.pop-enter-from .pop-content,
.pop-leave-to .pop-content {
  opacity: 0;
  transform: translate(-50%, -70%);
}
.pop-enter-to .pop-content,
.pop-leave-from .pop-content {
  opacity: 1;
  transform: translate(-50%, -50%);
}
.pop-content {
  background: #fff;
  border-radius: 10px;
  width: 400px;
  height: 120px;
  position: absolute;
  right: 24px;
  top: 24px;
  transition: all 0.5s;
}
.img-div {
  width: 64px;
  height: 64px;
  display: flex;
  border-radius: 50%;
  cursor: pointer;
  border: 1px solid #0077fa5c;
}
.img-div img {
  margin: auto;
}
</style>


